package com.wzh.forxu.base;

import android.content.Context;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.Toast;

import com.wzh.forxu.interfaces.AccountBookService;
import com.wzh.forxu.utils.HttpApi;

/**
 * @Author Hu
 * @Time 2017/4/21 --16:58.
 * @Email 87683202@qq.com
 */
public class BaseActivity extends AppCompatActivity {
    public Context context;
    public AccountBookService accountBookService;
    public HttpApi httpApi;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = this;
        httpApi = HttpApi.getInstance("http://10.0.0.11:8080/acc/");
        accountBookService = httpApi.getService(AccountBookService.class);
    }



    public void setTitleBar(Toolbar toolbar, String title) {
        toolbar.setTitle(title.trim());
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    public void setTitleBarNoBack(Toolbar toolbar, String title) {
        toolbar.setTitle(title.trim());
        setSupportActionBar(toolbar);

    }

    public void toast(Object o) {
        if (o instanceof Integer) {
            Toast.makeText(context, (Integer) o, Toast.LENGTH_SHORT).show();
        } else if (o instanceof CharSequence) {
            Toast.makeText(context, (CharSequence) o, Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(context, o + "", Toast.LENGTH_SHORT).show();
        }

    }
}
